Skip to content

Expand repeated sibling references in the MCP input schema - #3424

Merged
bnasslahsen merged 1 commit into
springdoc:mainfrom
mariodavid:fix/mcp-schema-converter-sibling-refs
Nov 6, 2026
Merged

bnasslahsen merged 1 commit into
springdoc:mainfrom
mariodavid:fix/mcp-schema-converter-sibling-refs

Conversation

@mariodavid

Copy link
Copy Markdown

Problem

OpenApiSchemaConverter.applySchemaToNode adds every visited schema to an identity-based visited set for cycle detection, but never removes it again. The set therefore contains all schemas seen so far in the tree, not only the ones on the current resolution path.

When two properties reference the same component (e.g. home and work both pointing to Address), the second occurrence is treated as a circular reference and emitted as a bare {"type":"object"}. Its properties are missing from the MCP tool input schema, so the schema is incomplete for any request body that reuses a component more than once.

Fix

Remove the schema from visited in a finally block once its branch has been converted, so the set only holds the current path. The previous method body moved unchanged into applySchemaContent. Real cycles are still cut off.

Tests

Two new tests in OpenApiSchemaConverterTest:

  • testSiblingReferencesToSameSchemaAreExpanded: two properties referencing the same component are both fully expanded. Fails without the fix.
  • testSiblingReferencesStillBreakCircularReferences: sibling references to a self-referencing component are both expanded, while the inner cycle is still cut off. Fails without the fix.

./mvnw -pl springdoc-openapi-starter-common-mcp test passes (34 tests).

OpenApiSchemaConverter added every visited schema to its cycle-detection set and never removed it again. When two properties referenced the same component, the second occurrence was treated as a circular reference and emitted as a bare {"type":"object"}, dropping its properties from the tool input schema.

Remove the schema from the set once its branch is converted, so the set only holds the current resolution path. Real cycles are still cut off.

Signed-off-by: Mario David <mario.david@faktorzehn.de>
bnasslahsen added a commit that referenced this pull request Nov 6, 2026
…ling-refs

Expand repeated sibling references in the MCP input schema. Fixes #3425
@bnasslahsen
bnasslahsen merged commit ceb72fc into springdoc:main Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants